<template>
    <div class="PRadioBox" @click="selectClick">
        <div :class="modelValue ==value?'active':'box'">
            <div v-show="modelValue==value">
                <i class="el-icon-check"></i>
            </div>
        </div>
        <div :class="modelValue ==value?'active-txt':'box-txt'">{{label}}</div>
    </div>
</template>

<script lang="ts">
import { defineComponent, reactive, toRefs } from "vue";
import { useStore } from "vuex";
/**
 * state 数据类型
 */
interface IState { }
export default defineComponent({
    name: "PRadioBox",
    props: {
        modelValue: {
            type: [String, Number, Boolean],
            default: ""
        },
        label: {
            type: String,
            default: "",
        },
        value: {
            type: [String, Number, Boolean],
            default: ""
        },
        isSee: {
            type: Boolean,
            default: false
        }
    },
    emits: ["update:modelValue", "change"],
    setup(props, { emit }) {
        const store = useStore();
        const { UIAuth, bodySize } = store.state;
        const state = reactive<IState>({});
        function selectClick() {
            if (!props.isSee) {
                if (props.modelValue === props.value) {
                    emit("update:modelValue", "");
                    emit("change", "");
                } else {
                    emit("update:modelValue", props.value);
                    emit("change", props.value);
                }
            }
        }
        return {
            UIAuth,
            bodySize,
            ...toRefs(state),
            selectClick
        };
    },
});
</script>

<style scoped lang="scss">
.PRadioBox {
    display: flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
    & > div {
        &:nth-child(1) {
            margin-right: 5px;
            border-radius: 2px;
            width: 12px;
            transition: all 0.2s ease;
            height: 12px;
            &:hover {
                border: 1px $primary-color solid;
            }
            & > div {
                width: 100%;
                height: 100%;
                display: flex;
                align-items: center;
                justify-content: center;
                & > i {
                    font-size: 12px;
                    transform: scale(0.9);
                }
            }
        }
    }
    & > .box {
        color: $text-primary-color;
        border: 1px #dcdfe6 solid;
        background-color: #fff;
    }
    & > .active {
        color: #fff;
        background-color: $primary-color;
        border: 1px $primary-color solid;
    }
    &:hover {
        cursor: pointer;
    }
    & > .box-txt {
        color: $text-primary-color;
    }
    & > .active-txt {
        color: $primary-color;
    }
}
</style>